const data = {
  name: "djk",
  age: 18,
  count: 10,
};
function reducer(state = data, action) {
  console.log("接收到action", action);
  if (action.type === "ADD_NUM") {
    let num = state.count + action.num;
    // console.log(num);
    // 如果reducer处理的是一个复杂的对象，则需要在改变它单独的一个
    // 属性的时候，需要把整个的对象都给他复制一遍
    return { ...state, ...{ count: num } };
  } else if(action.type==='SUB_NUM'){
    let num = state.count - action.num;
    return { ...state, ...{ count: num } };
  }
  return state;
}

// 如果保存的数据是单独的一个，可以这么干
// function reducer(state = 0, action) {
//   console.log("接收到action", action);
//   if (action.type === "ADD_NUM") {
//     return state + action.num;
//   }
//   return state;
// }

export default reducer;
